package com.ajx.cube.module.splash.lancher;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.ajx.core.app.Cube;
import com.ajx.cube.R;
import com.ajx.cube.common.Constants;

import com.ajx.cube.module.login.LoginActivity;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lai on 2017/12/7.
 */

public class LauncherActivity extends AppCompatActivity{
    private ConvenientBanner convenientBanner;
    private List<Integer> images=new ArrayList<>() ;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        hideBottomUIMenu();
        convenientBanner = (ConvenientBanner) findViewById(R.id.convenientBanner);
        convenientBanner.setCanLoop(false);

        images.add(R.mipmap.ic_launcher);
        images.add(R.mipmap.ic_launcher_round);
        convenientBanner.setPages(
                new CBViewHolderCreator<LauncherViewHolder>() {
                    @Override
                    public LauncherViewHolder createHolder() {
                        LauncherViewHolder launcherViewHolder = new LauncherViewHolder(images.size());
                        launcherViewHolder.setOnEnterClickListener(new LauncherViewHolder.OnEnterClickListener() {
                            @Override
                            public void onEnterClick() {
                                startActivity(new Intent(LauncherActivity.this, LoginActivity.class));
                                Cube.getSp().put(Constants.SpFlag.FIRST_LAUNCH,false);
                                finish();
                            }
                        });
                        return launcherViewHolder;
                    }
                }, images)
                //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                .setPageIndicator(new int[]{R.drawable.ic_page_indicator, R.drawable.ic_page_indicator_focused})

                //设置指示器的方向
                //.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT)
                //监听翻页事件
                //.setOnPageChangeListener(this)
                .setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(int position) {

                    }
                });
        convenientBanner.setcurrentitem(0);

    }

    protected void hideBottomUIMenu() {
        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }
}
